var subjectCategoryType;
var id;
var groupid;
var iconid;
var subid;
var menuid;
var backstage_access_personnelstyle;
$(function() {
	groupid = ly.getUrlParam("groupid");
	iconid = ly.getUrlParam("iconid");
	subid = ly.getUrlParam("subid");
	menuid = ly.getUrlParam("menuid");

	backUserType = ly.getUrlParam("backUserType");
	backstage_access_personnelstyle = window.localStorage.getItem("backstage-access-personnelstyle");
	if(backstage_access_personnelstyle == "2") {
		$(".changeTeam").hide();
		$(".changeWork").hide();
	}
	id = ly.getUrlParam("id");
	if(backUserType == 2) {
		$(".body_title").html("编辑");
		$(".form").getForm({
			id: id,
			ajaxform: true
		}, function(data) {

			if(data.fileUpload!=null){
				$('.imgbox').find('img').attr('src', data.fileUpload.url)
			}

			$("#isUsing").getSelect({
				type: "radio",
				asName: "isUsing",
				list: [{
						value: "1",
						display: "启用"
					},
					{
						value: "0",
						display: "禁用"
					}
				],
				default: data.isUsing
			});
		});
	} else {

		$("#isUsing").getSelect({
			type: "radio",
			asName: "isUsing",
			list: [{
					value: "1",
					display: "启用"
				},
				{
					value: "0",
					display: "禁用"
				}
			],
			default: '1'
		});
	}



	//提交
	$("body").on("click", "#save-btn-commodityClassification", function(event) {
		event.preventDefault();

		var success = $('.form').validate('submitValidate');
		if(success) {
				//验证通过提交表单
				submitFom();
		}
	})


	//批量删除
	$("#batchDelBtn").click(function() {
		var c = "";
		$("input[name=datachk]:checked").each(function() {
			c += $(this).val() + ',';
		});
		deleteFirstCategory(c);
	});
});

/*
 * 提交表单
 */
function submitFom() {
	var account = $("#account").val();
	//var password =md5($("#password").val());
	var nickName = $("#nickName").val();

	var isUsing = $("#isUsing input:checked").val();

	var fileName = $('#bPicUrl input').attr('filename');
	var filePath = $('#bPicUrl input').attr('value');
	var fileType = $('#bPicUrl input').attr('filetype');
	var fileSize = $('#bPicUrl input').attr('filesize');

	var obj = {};
	var url = site.gateUrl + "/back/backUser/insertOrUpdateScenicBackUser";
	var f = { //图标
		'fileName': fileName,
		'filePath': filePath,
		//'fileType':fileType,
		'fileSize': fileSize
	};

	if(backUserType == 1) {
		//新增
		obj = {
			//账户
			'account': account,
			//昵称
			'nickName': nickName,
			//是否启用
			'isUsing': isUsing
		};
	} else {
		//修改
		var thisId = $("#id").val();
		obj = {
			//账户
			'account': account,
			//昵称
			'nickName': nickName,
			//是否启用
			'isUsing': isUsing,
			'id': thisId
		};
	}
	//头像文件实体
	obj.headPortraitFile = f;
	console.log(obj);
	request({
		url: url,
		data: obj,
		type: "post",
		callback: function(f) {
			console.log(f);
			if(f.code == "rest.success") {
				if(backUserType == 1) {
					ly.alert('保存成功', function() {
						ly.goto("../backUser.html");
					});
				} else {
					ly.alert('修改成功', function() {
						ly.goto("../backUser.html");
					});
				}
			} else {
				ly.toast(f.desc);
			}
		}
	});

}


